package com.arch.dev.client.view;

import com.arch.dev.client.controller.BudgetController;
import com.arch.dev.client.vo.BudgetVO;
import com.arch.dev.client.vo.UserVO;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Widget;

public class UserDialogView extends DialogBox  {

	private static UserDialogViewUiBinder uiBinder = GWT
			.create(UserDialogViewUiBinder.class);

	interface UserDialogViewUiBinder extends UiBinder<Widget, UserDialogView> {
	}
	
	@UiField
	public UserFormView formView;

	private Widget widget;

	public UserDialogView(final Widget widget) {
		super(false,true);
		this.widget = widget;
		Widget w = uiBinder.createAndBindUi(this);
		setText("Add Details");
		setSize("100%", "100%");
		setGlassEnabled(true);
		//setAnimationEnabled(true);		
		setWidget(w);		
		
		formView.saveButtonAddClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				BudgetController.getInstance().persistUserValues(widget,
						formView.populateVo());
				hide();
			}
		});

		formView.getCancelButton().addClickHandler(new ClickHandler() {
			
			public void onClick(ClickEvent event) {
				hide();
				
			}
		});
		

	}

	public void show()

	{
		int ph = getOffsetHeight();

		int pw = getOffsetWidth();

		int wh = Window.getClientHeight();

		int ww = Window.getClientWidth();

		int locx = (ww - pw - getOffsetWidth()) / 3;

		int locy = (wh - ph - getOffsetHeight()) / 3;

		super.setPopupPosition(locx, locy);

		super.show();

	}
	
	public void populateFormFields(UserVO userVO){
		formView.populateFormFields(userVO);
	}
	
	public void initFormFields(){
		formView.initFormFields();
	}
}
